package com.mornd.gulimall.seckill.controller;

import com.mornd.gulimall.seckill.entity.SeckillNowVo;
import com.mornd.gulimall.seckill.service.ISeckillService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;

/**
 * @author: mornd
 * @dateTime: 2023/8/30 - 6:41
 * 操作需要登录
 */

@Controller
public class AuthSeckillController {

    @Resource
    private ISeckillService seckillService;

    @GetMapping("/userseckillnow")
    public String seckillnow(@Validated SeckillNowVo seckillNowVo, Model model) {
        try {
            String sn = seckillService.seckillnow(seckillNowVo);
            model.addAttribute("orderSn", sn);
        } catch (Exception e) {
            model.addAttribute("error", "秒杀失败，" + e.getMessage());
        }
        return "success";
    }
}
